<template>
  <div>
      <public-search
              :fields="fields"
              :search-param="form"
              @on-query="onQuery"
              @on-reset="onReset"
      />
      <public-table
              :page="page"
              :height="'500'"
              :tableData="tableData"
              :tableOption="tableOption"
              @pageChange="pageChange"
      ></public-table>
  </div>
</template>

<script setup>
import PublicSearch from "@/components/PublicSearch.vue";
import PublicTable from "@/components/PublicTable.vue";
import {onMounted, reactive, ref} from "vue";
import {projectTaskImplementation} from "@/api/taskImplementation";
import {resetForm} from "@/common/utils/GlobalUtils";

const form = ref({});
const fields = ref([
    {
        type:'input',
        label:'任务名称',
        key:'taskName',
        placeholder:'请输入任务名称',
        clearable:true
    },
    {
        type:'datetimerange',
        label:'时间范围',
        key:'valueTime',
        startTimeName:'startDate',
        endTimeName:'endDate',
        placeholder:'请选择时间范围',
        clearable:true,
        fun:(e,params)=>{
            if(e && e instanceof Array && e.length>0){
                form.value[params.startTimeName] = e[0];
                form.value[params.endTimeName] = e[1];
            }
            if(!e || (e instanceof  Array && e.length===0)){
                form.value[params.startTimeName] = '';
                form.value[params.endTimeName] = '';
            }
        }
    },
]);

const page = reactive({
    total: 0,
    current: 1,
    size: 50,
});
const tableData = ref([]);
const tableOption = ref([
    { label: "审批状态 ", prop: "status",  formatter: (val,row) => {
            let obj = {'1':'审批中','2':'已通过','3':'已驳回'}
            return obj[val] || '-';
        },
    },
    { label: "审批单标题 ", prop: "flowTitle" },
    { label: "关联项目 ", prop: "projectName" },
    { label: "关联任务 ", prop: "taskName" },
    { label: "审批单编号 ", prop: "summaryId" },
    { label: "发起人 ", prop: "responsibleUserName" },
    { label: "创建时间 ", prop: "applyTime" },
    { label: "完成时间 ", prop: "approvalTime" },
]);


/**
 * 协同审批
 */
const getCollaborativeApprovalList = (params) => {
    projectTaskImplementation.getCollaborativeApprovalList(params).then(res=>{
        if(res.code==='200'){
            tableData.value = res.data.content;
            page.total = res.data.totalSize;
        }
    })
}

/**
 * 条件查询
 */
const onQuery = () => {
    page.current = 1;
    page.size = 50;
    let param = {
        param: {
          ...form.value
        },
        pageNum: page.current,
        pageSize: page.size,
    };
    getCollaborativeApprovalList(param);
}

/**
 * 重置
 */
const onReset = () => {
    resetForm(form.value);
    page.current = 1;
    page.size = 50;
    let param = {
        pageNum: page.current,
        pageSize: page.size,
    };
    getCollaborativeApprovalList(param);
}


/**
 * 分页
 */
const pageChange = (e) => {
    page.current = e.page;
    page.size = e.limit;
    let param = {
        param: {
            ...form.value
        },
        pageNum: page.current,
        pageSize: page.size,
    };
    getCollaborativeApprovalList(param);
}

onMounted(()=>{
    getCollaborativeApprovalList({pageNum:1,pageSize:50});
});
</script>

<style scoped>

</style>